import {
  checkLogin
} from './auth.js'
new Vue({
  el: '#app',
  data: {
    IS_LOGIN: null,
    searchKey: '', // 搜索的关键词
    orderList: []
  },
  async created() {
    this.IS_LOGIN = await checkLogin()
    if (this.IS_LOGIN == null) {
      location.href = '/'
    }
    this.getOrders(null)
  },
  methods: {
    async getOrders(state) {
      let res = 0;
      if (state == null || state == '') {
        res = await request.get('/order/getOrderListByUserState')
      }else { 
        console.log('state:',state);
        res = await request.get('/order/getOrderListByUserState',{
          params:{
            state: state
          }
        })
      }
      this.orderList = res.data
      console.log(this.orderList);
    },
    // 查找商品
    searchProduct() {
      console.log('查找商品:');
      location.href = `../web/search.html?searchKey=${this.searchKey}`
    },
    // 退出登录
    logout() {
      localStorage.removeItem('token')
      this.IS_LOGIN = null
      location.href = '/'
    },
  }
})